import 'package:dog_read/pages/book/search/search_list.dart';
import 'package:flutter/material.dart';
import 'package:dog_read/pages/book/chapter/chapter_content.dart';
import 'package:dog_read/pages/book/chapter/chapter_list.dart';
import "package:dog_read/taps/bottom_taps.dart";
import 'package:dog_read/pages/book/book.dart';
import 'package:dog_read/pages/more/more.dart';
import 'package:dog_read/pages/book/book_detail.dart';

// 命名路由写这里
final routes = {
  "/": (context) => BottomTaps(),
  "/book": (context) => Book(),
  "/book/detail": (context, {arguments}) => BookDetail(arguments: arguments,),
  "/chapter": (context) => ChapterList(),
  "/chapter/content": (context) => ChapterContent(),
  "/book/search": (context) => BookSearchList(),
  "/more": (context) => More(),
};

Function onGenerateRoute = (RouteSettings routeSettings) {
  /**
   * 自定义的可传参的路由生成器
   */
  final String name = routeSettings.name;
  final Function pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (routeSettings.arguments != null) {
      final Route route = MaterialPageRoute(
        builder: (context) => pageContentBuilder(context, arguments: routeSettings.arguments));
      return route;
    } else {
      final Route route = MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  } else {
    return null;
  }
};

// Function onGenerateRoute = (RouteSettings settings) {
//   print(settings.name);
//   final Function pageContentBuilder = routes[settings.name];
//         switch (settings.name) {
//           case '/chapter/content': 
//             return new MyCustomRoute(
//               builder: (context) => pageContentBuilder(context),
//               settings: settings,
//             );
//             break;
//           default:
//             return MaterialPageRoute(builder: (context) => pageContentBuilder(context));
//             break;
//         }
//       };

// class MyCustomRoute<T> extends MaterialPageRoute<T> {
//   MyCustomRoute({ WidgetBuilder builder, RouteSettings settings })
//       : super(builder: builder, settings: settings);

//   @override
//   Widget buildTransitions(BuildContext context,
//       Animation<double> animation,
//       Animation<double> secondaryAnimation,
//       Widget child) {
//     if (settings.isInitialRoute)
//       return child;
//     // Fades between routes. (If you don't want any animation, 
//     // just return child.)
//     return new FadeTransition(opacity: animation, child: child);
//   }
// }